<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText" :titleExplain="titleExplain"></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="用人单位" class="row-padding-bottom">
              <el-input
                placeholder="名称或统一社会信用代码"
                clearable
                v-model="filterField.companyName"
                @blur="filterField.companyName = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="单位类型" class="row-padding-bottom">
              <el-select
                v-model="filterField.departmentType"
                placeholder="请选择"
                clearable
                :popper-append-to-body="false"
              >
                <el-option label="企业" value="0"></el-option>
                <el-option label="事业单位" value="5"></el-option>
                <el-option label="个体工商户" value="15"></el-option>
                <el-option label="其他" value="10"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="账号" class="row-padding-bottom">
                <el-input
                  placeholder="请输入账号"
                  clearable
                  v-model="filterField.userName"
                  @blur="filterField.userName = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>

            <!-- <el-form-item>
                        <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchTable" class="commonBtn"></el-button>
                    </el-form-item> -->
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchTable"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableData.length"
                :filterField="filterField"
                :api="api"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <!-- 列表 -->
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <!-- <el-table-column align="center" prop="companyName" label="单位名称" width="120px" :formatter=formatTd></el-table-column> -->
          <el-table-column label="单位名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.companyName"
                :columnName="'companyName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="uscc"
            label="统一社会信用代码"
            :formatter="formatTd"
            min-width="200"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="departmentName"
            label="单位类型"
            :formatter="formatTd"
            min-width="120"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="boss"
            label="法人/经营者名称"
            :formatter="formatTd"
            min-width="150"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="bossTel"
            label="法人/经营者联系方式"
            :formatter="formatTd"
            min-width="180"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="username"
            label="账号"
            :formatter="formatTd"
            min-width="120"
          ></el-table-column>
          <el-table-column align="left" label="操作" fixed="right" width="110">
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="toDetail(scope.row)"
                v-if="isShowDetail"
                >管理资料</el-link
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'employerInfoList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '用人单位信息维护',
      advanced: false,
      titleExplain:
        '单位信息可由单位自由维护，也可由监管进行补充修改，当单位无法修改密保手机号时，监管可协助修改',
      requestUrl: 'api-c/company/expand/compuserlist', //表格请求路径
      date: [], //申请日期
      loading: true,
      isShow: false,
      tableData: [], //表格数据
      filterField: {
        departmentType: '', //单位类型
        companyName: '', //申请企业名称/代码
        userName: '',
      },
      pageSize: 20,
      pageNo: 1,
      isShowDetail: '',
      api: '',
    }
  },
  created() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getApi()
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('employerInfoList:detail') > -1
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      this.pageSize = 20
      this.pageNo = 1
      this.$refs.pagination.getTableListData()
    },
    //跳转详情页面
    toDetail(row) {
      this.$router.push({
        name: 'employerRecordDetail',
        path: '/home/enterpriseSet/employerRecordDetail',
        query: {
          companyId: row.companyId,
          routeName: 'employerInfoList',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/enterpriseSet/employerInfoList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getApi() {
      if (localStorage.getItem('judgeRoleCode') === 'company') {
        this.api = 'api-s/report/export_JC_NC_COMPANY_INFO'
      } else {
        this.api = 'api-s/report/export_JC_CS_COMPANY_INFO'
      }
    },
  },
}
</script>

<style scoped lang="less">
@import '../../../static/css/filterArea.less';
.mainCon {
  top: 198px;
}
@media only screen and (max-width: 1366px) {
  /deep/.searchInputWidth .el-form--inline .el-form-item__label {
    width: 80px;
  }
}
</style>
